<?php

class Core_Model_Promotion_Position extends Dcmp_Model_Spoor {

    public function __construct() {
        parent::__construct();
    }

    public function validate() {
        if ($this->isNew()) {
            $result = Kd_Data_Factory::getQueryDcl()
                            ->from('{t}promotion_position')->select()->field('code')->closest()->where()
                            ->eq('code', ':code:s')->closest()->addParameter('code', $this->getCode())->fetch()->getFirstValue();
            if (!$result)
                return TRUE;
            else
                return 'The code is already existed';
        }
        return TRUE;
    }

    protected function initializeTable($table) {
        $table->setName('{t}promotion_position');
        $table->createColumn('id', 'integer', TRUE, TRUE);
        $table->createColumn('code', 'string');
        $table->createColumn('name', 'string');
        $table->createColumn('height', 'integer');
        $table->createColumn('width', 'integer');
        parent::initializeTable($table);
    }

}